import { getItem } from '../../utils/storage'
import { TOKEN, SAVE_TOKEN, REMOVE_TOKEN} from '../../utils/constant'

const tokenInfo = getItem(TOKEN)
const initState = {
    token: tokenInfo,
    isLogin: tokenInfo ? true : false // 用户登录状态
}
export default function loginReducer (preState=initState, action) {
    const { type, data } = action
    switch (type) {
        case SAVE_TOKEN:
            return {...data}
        case REMOVE_TOKEN:
            return {...data}
        default:
            return preState
    }
}